import { Message, MessageBox } from 'element-ui'
import log from './logReport'

/**
 * 删除记录时弹出确认框确认
 * @param {String} type     删除记录的名称：例如 菜单、用户
 * @param {String} reportsWitch   埋点上报开关: 为ture上报
 */
export function confirmBox(
  type = '记录',
  operate = '永久删除',
  reportsWitch = true
) {
  return new Promise((resolve, reject) => {
    MessageBox.confirm('此操作将' + operate + type + ', 是否继续?', '提示', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning'
    })
      .then(() => {
        resolve()
      })
      .catch(() => {
        if (reportsWitch) {
          log.event(type, 'cancel', '取消' + type + operate)
        }
        // Message({
        //     type: 'info',
        //     message: '已取消此操作'
        // });
        reject()
      })
  })
}
